import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Clase que pinta una explosion al tocar un blanco falso.
 * 
 * @author Gabriel
 * @version 1.0
 */
public class Explosion extends Actor
{
    /** Numero de imagenes usadas para la explosion */
    private final static int IMAGE_COUNT= 5;
    
    private static GreenfootImage[] images;
    
    /** Tamaño de la explosion */
    private int size=0;
    private int increment=1; 
    
    /**
     * Constructor de la clase Explosion.
     */    
    public Explosion()
    {
        initialiseImages();
        setImage(images[0]);        
        Greenfoot.playSound("Explosion.wav");
    }    
    
    /** 
     * Este metodo crea las imagenes para la explosion.
     */
    public synchronized static void initialiseImages()
    {
        if(images == null) {
            GreenfootImage baseImage = new GreenfootImage("explosion.png");
            int maxSize = baseImage.getWidth()*4;
            int delta = maxSize / (IMAGE_COUNT+1);
            int size = 0;
            images = new GreenfootImage[IMAGE_COUNT];
            for(int i=0; i < IMAGE_COUNT; i++) {
                size = size + delta;
                images[i] = new GreenfootImage(baseImage);
                images[i].scale(size, size);
            }
        }
    }
    
    /**
     * En el metodo act la explosion se hace animar.
     */
    public void act()
    { 
        setImage(images[size]);

        size += increment;
        if(size>=IMAGE_COUNT) {
            increment = -increment;
            size += increment;
        }
        
        if(size <= 0) {
            getWorld().removeObject(this);
        }
        
        
    }
    
 
}
